package com.ruoyi.common.utils.exception;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 党怡承
 * @since 2021-08-09
 */
@RestControllerAdvice
public class GlobalException {

  @ExceptionHandler(value = CustomException.class)
  @ResponseBody
  public static JSONObject globalException(CustomException ex) {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("errorCode", ex.getErrorCode());
    jsonObject.put("errorMessage", ex.getErrorMessage());
    return jsonObject;
  }
}
